<template>
    <div class="cataBox">
        <div class="cataBox" v-for="(item,index) in catalog" :key="index">
            <div class="cataTitle" @click.prevent="currentCataId=item.id">
                <div>
                    <b>第{{exchangeIndex(index+1)}}节</b>
                    {{item.title}}
                </div>
                <div>
                    <span @click="openCata(1,item.rank)">插入</span>
                    <span @click="editChapter(item)">修改</span>
                    <confirmBox
                        @handleOk="deleteChapter(item.id)"
                        :typeName="'删除'"
                        :noticeInfo="item.title"
                        :noticeType="'章节'"
                    ></confirmBox>
                    <span @click="openTaskModal(item)">添加学习任务</span>
                </div>
            </div>
            <div class="taskList" v-if="currentCataId==item.id">
                <div class="taskBox" v-for="(value,taskIndex) in item.tasks" :key="taskIndex">
                    <div>
                        <span v-if="value.type==0">【视频】</span>
                        <span v-else-if="value.type==1">【资料】</span>
                        <span v-else-if="value.type==2">【习题】</span>
                        <span v-else>【考试】</span>
                        {{value.title}}
                    </div>
                    <div class="right">
                        <span @click="openTaskModal(item,value.rank)">插入</span>
                        <span v-if="item.tasks.length>1&&taskIndex!=0" @click="taskMove(value.id,'up')">上移</span>
                        <span v-if="item.tasks.length>1&&taskIndex!=item.tasks.length-1" @click="taskMove(value.id,'down')">下移</span>
                        <span @click="editTask(value)">修改</span>
                        <confirmBox
                            @handleOk="deleteTask(value.id)"
                            :typeName="'删除'"
                            :noticeInfo="value.title"
                            :noticeType="'任务'"
                        ></confirmBox>
                        <span @click="setFree(value)">{{value.isFree==0?'设为试看':'取消试看'}}</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>